package com.yyt.module_main.fragment;

import com.chad.library.adapter.base.BaseViewHolder;
import com.yyt.libsrc.bean.PrepaidListBean;
import com.yyt.libsrc.bean.RateOfTheWaterBean;
import com.yyt.libsrc.conf.Consts;
import com.yyt.libsrc.helper.LocalHelper;
import com.yyt.libsrc.helper.MsgHelper;
import com.yyt.libsrc.net.JavaParamsBuilder;
import com.yyt.libsrc.net.NetUtil;
import com.yyt.libsrc.net.SuccessCallback;
import com.yyt.module_main.R;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import top.lixb.libcommon.base.RefreshListFragment;
import top.lixb.libcommon.view.SimpleItemView;

public class RechargeOrderFragment extends RefreshListFragment<RechargeOrderFragment.ItemBean> {

    private List<ItemBean> mItemBeans;
    @Override
    protected void getData(final boolean refresh) {
        NetUtil.sellerPost(new JavaParamsBuilder()
                .addCmd(Consts.CMD.PrepaidList)
                .addP("sid", LocalHelper.getSid())
                .build(), new SuccessCallback<PrepaidListBean>() {
            @Override
            public void onSuccess(PrepaidListBean getOrderBean) {
                mItemBeans = new ArrayList<>();
                if (getOrderBean.data!=null) {
                    for (PrepaidListBean.DataBean dataBean : getOrderBean.data) {
                        if (dataBean.consumption_type!=3) {
                            ItemBean itemBean = new ItemBean();
                            itemBean.amount = dataBean.price;
                            itemBean.consumption_type = dataBean.consumption_type;
                            itemBean.create_at = dataBean.createTime;
                            mItemBeans.add(itemBean);
                        }
                    }
                }
                getModifyRateList();
            }

        });
    }



    public static class ItemBean{
        public int consumption_type;
        public String create_at;
        public String amount;
    }

    private void getModifyRateList() {
        NetUtil.sellerPost(new JavaParamsBuilder()
                .addCmd(Consts.CMD.RateOfTheWater)
                .addP("operator",LocalHelper.getSid())
                .build(), new SuccessCallback<RateOfTheWaterBean>() {
            @Override
            public void onSuccess(RateOfTheWaterBean rateOfTheWaterBean) {
                if (null!=rateOfTheWaterBean.data) {
                    for (RateOfTheWaterBean.DataBean bean : rateOfTheWaterBean.data) {
                        ItemBean itemBean = new ItemBean();
                        try {
                            itemBean.create_at = mSimpleDateFormat.format(new Date(Long.valueOf(bean.create_time)));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        itemBean.consumption_type = 3;
                        itemBean.amount = String.valueOf(bean.price);
                        if (null != mItemBeans) {
                            mItemBeans.add(0,itemBean);
                        }
                    }
                }
                setData(mItemBeans);
            }

            //20180822144247

        });
    }

    private SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    protected int getItemLayout() {
        return R.layout.item_recharge_order;
    }

    @Override
    protected void bind(BaseViewHolder holder, ItemBean item) {
        String desc = "";
        int imgId = R.mipmap.icon_index_partent;
        switch (item.consumption_type) {
            case 1:
                desc = "充值合伙人";
                imgId = R.mipmap.icon_cz_1;
                break;
            case 2:
                desc = "充值代理商";
                break;
            case 3:
                desc = "修改费率";
                imgId = R.mipmap.icon_cz_2;
                break;
        }
        SimpleItemView itemView = holder.getView(R.id.item_view);
        itemView.setLeftIcon(getResources().getDrawable(imgId));
        itemView.setLeftTopText(desc);
        itemView.setLeftBottomText(item.create_at);
        itemView.setRightTopText(item.amount);

    }


}
